<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers                           |
// |                                                                      |   
// | http://www.zen-cart.com/index.php                                    |   
// |                                                                      |   
// | Portions Copyright (c) 2003 osCommerce                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.zen-cart.com/license/2_0.txt.                             |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to       |
// | license@zen-cart.com so we can mail you a copy immediately.          |
// +----------------------------------------------------------------------+
// $Id: jscript_main.php 1105 2005-04-04 22:05:35Z birdbrain $
//
?>
<!--Vu - add script to using jquery-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script language="javascript" type="text/javascript">
    function popupWindow(url) {
        window.open(url, 'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
    }

</script>
<script>
    $(document).ready(function() {
        $(document).on("click", ".wrapchild input", function() {
            $(this).removeClass('messageStackError');
        });
        $(document).on("click", ".wrapchild textarea", function() {
            $(this).removeClass('messageStackError');
        });
        $(document).on("click", ".comment-button", function() {
            $(this).hide();
            orders_id = $(this).attr('id');
            $(this).parent().after(template_comment(orders_id));
            return false;
        });
        $(document).on("click", ".child-comment", function() {            
            var parentid = $(this).attr('parentid');
            var titlechild = '';
            var contentchild = $('.wrapchild textarea').val();
            var languages_id = <?php echo $_SESSION['languages_id']; ?>;
            var products_id = <?php echo $_GET['products_id']; ?>;
            var customer_id = <?php echo $_SESSION['customer_id']; ?>;
            var child = $(this).parent().parent().attr('class');
            var ordersid = $(this).attr('id');
            if(contentchild.length <= 50){
                alert('Please enter messages greater than 50 characters');
                $('.wrapchild textarea').addClass('messageStackError');
                return false;
            }
            $.ajax({
                type: "POST",
                async: false,
                url: 'ajax_comment.php',
                data: {parentid: parentid, titlechild: titlechild, contentchild: contentchild, languages_id: languages_id, products_id: products_id, customer_id: customer_id, child: child},
                success: function(data) {
                    if (data != "") {
                        console.log(data);
                        value = data.split('*_id_*');
                         value_data = value.data;
                         value_id = value.parentid;
                        //blur this button
                        $('.wrapchild').remove();
                        $("#"+value[0]).show();
                        $("#"+value[0]).parent().parent().after(value[1]);                        
                    }
                }
            });
        });
    });
    function template_comment(data) {
        var datatemplate = '<div class="wrapchild"><h3>Please tell us what you think and share your opinions with others. Be sure to focus your comments on the product.</h3>                        \n\
                            <textarea id="review-text" rows="5" cols="60" name="review_text"></textarea>\n\
                            <input type="image" title=" Submit the Information " alt="Submit the Information" src="includes/templates/template_default/buttons/english/button_submit.gif" parentid="' + data + '" class="child-comment"></div>';
        return datatemplate;
    }
</script>
